import { ipcMain } from 'electron';
import Subject from '../models/Subject';
export default class SubjectService {
  constructor() {
    this._registerListing();
  }
  _registerListing = () => {
    console.log('register SubjectService');
    ipcMain.on('asynchronous-message', function(event, arg) {
      event.sender.send('asynchronous-reply', 'pong');
    });

    //获取科目列表
    ipcMain.on('subject-getall', (event, arg) => {
      console.log('subject-getall'); // prints "ping"
      Subject.getAllSubject(arg).then(value => {
        event.sender.send('subject-getall-replay', value);
      });
    });

    //获取科目总账
    ipcMain.on('subject-getreport', (event, arg) => {
      console.log('subject-getreport'); // prints "ping"
      Subject.getVoucherReportBySubjectCode(arg).then(value => {
        event.sender.send('subject-getreport-replay', value);
      });
    });

    //新增科目
    ipcMain.on('subject-insert', (event, arg) => {
      console.log('subject-insert');
      Subject.subjectInsert(arg).then(value => {
        event.sender.send('subject-insert-replay', value);
      });
    });

    //新增期初金额
    ipcMain.on('subjectSummary-save', (event, arg) => {
      console.log('subjectSummary-save');
      Subject.subjectSummaryInsert(arg).then(value => {
        event.sender.send('subjectSummary-save-replay', value);
      });
    });

    //更新科目状态
    ipcMain.on('subject-update-status', (event, arg) => {
      console.log('subject-update-status');
      Subject.updateStatus(arg).then(value => {
        event.sender.send('subject-update-status-replay', value);
      });
    });
  };
}
